import sys
import os

# 将 src 目录添加到 Python 路径中，以便导入我们自己的模块
# This allows us to import our own modules from the src directory
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
# 导入路径管理器和模块
from src.utils import CONFIG_PATH, DATABASE_PATH, SCHEMA_PATH
from src.database import Database

def main():
    """
    使用从 .env 加载的路径来初始化数据库。
    Initializes the database using paths loaded from the .env file.
    """
    print("Attempting to initialize the database...")
    print(f"  - Database file: {DATABASE_PATH}")
    print(f"  - Schema file: {SCHEMA_PATH}")

    try:
        # 直接使用绝对路径初始化 Database
        with Database(db_path=str(DATABASE_PATH)) as db:
            db.initialize_schema(schema_path=str(SCHEMA_PATH))
    except Exception as e:
        print(f"\nAn error occurred during database initialization: {e}")

if __name__ == '__main__':
    main()
